#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <SDL2/SDL.h>
#include <unistd.h>


SDL_Window* swindow ;
SDL_Renderer* srender;

int sdl_main_loop(void *window)
{
    sleep(2);
    QWidget *widget = (QWidget *)window;

    int iii = SDL_GetNumRenderDrivers();
    SDL_Window* swindow = SDL_CreateWindowFrom((void*)widget->winId());
     SDL_Renderer* srender = SDL_CreateRenderer(swindow, 1, SDL_RENDERER_ACCELERATED);
    /* SDL_Renderer* srender = SDL_CreateRenderer(swindow, -1, SDL_RENDERER_SOFTWARE | SDL_RENDERER_ACCELERATED); */
    //SDL_Renderer* srender = SDL_CreateRenderer(swindow, -1, SDL_RENDERER_SOFTWARE);

    SDL_SetRenderDrawColor(srender, 0, 34, 0, 255);
    SDL_RenderFillRect(srender, NULL);
    SDL_RenderPresent(srender);
}

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    SDL_Init(SDL_INIT_VIDEO);

    SDL_CreateThread(sdl_main_loop, "test1", (void *)this);

    /* SDL_Window* swindow = SDL_CreateWindowFrom((void*)this->winId()); */
    /* SDL_Renderer* srender = SDL_CreateRenderer(swindow, -1, SDL_RENDERER_SOFTWARE | SDL_RENDERER_ACCELERATED); */

    /* SDL_SetRenderDrawColor(srender, 0, 0, 0, 255); */
    /* SDL_RenderFillRect(srender, NULL); */
    /* SDL_RenderPresent(srender); */


}

MainWindow::~MainWindow()
{
    SDL_DestroyWindow(swindow);
    SDL_DestroyRenderer(srender);
    SDL_Quit();

    delete ui;
}
